package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fgs.common.utils.LogUtil;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.FindCarDeliveryInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2021/8/10
 * @description
 */
public class FindCarListAdapter extends RecyclerArrayAdapter<FindCarDeliveryInfo.CarRecords> {
    public FindCarListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new FindCarListViewHolder(parent, R.layout.item_find_car_list);
    }

    private class FindCarListViewHolder extends BaseViewHolder<FindCarDeliveryInfo.CarRecords> {

        private final TextView tvHuoquanTitle;
        private final TextView tvHuoquanNum;
        private final TextView tvXiaohuoTitle;
        private final TextView tvXiaohuoNum;
        private final TextView tvMudiTitle;
        private final TextView tvMudiNum;
        private final TextView tvZongliangTitle;
        private final TextView tvZongliangNum;
        private final TextView tvBeizhuTitle;
        private final TextView tvBeizhuNum;
        private final TextView  tv_cunhuo_num;
        private final TextView  tv_chandi_num;
        private final TextView  tv_kehu_title;
        private final TextView  tv_kehu_num;



        public FindCarListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            tvHuoquanTitle = getView(R.id.tv_huoquan_title);
            tvHuoquanNum = getView(R.id.tv_huoquan_num);
            tvXiaohuoTitle = getView(R.id.tv_xiaohuo_title);
            tvXiaohuoNum = getView(R.id.tv_xiaohuo_num);
            tvMudiTitle = getView(R.id.tv_mudi_title);
            tvMudiNum = getView(R.id.tv_mudi_num);
            tvZongliangTitle = getView(R.id.tv_zongliang_title);
            tvZongliangNum = getView(R.id.tv_zongliang_num);
            tvBeizhuTitle = getView(R.id.tv_beizhu_title);
            tvBeizhuNum = getView(R.id.tv_beizhu_num);
            tv_cunhuo_num = getView(R.id.tv_cunhuo_num);
            tv_chandi_num = getView(R.id.tv_chandi_num);
            tv_kehu_title = getView(R.id.tv_kehu_title);
            tv_kehu_num = getView(R.id.tv_kehu_num);

        }

        @Override
        public void setData(FindCarDeliveryInfo.CarRecords data) {
            super.setData(data);

            tvHuoquanNum.setText(data.getHq());
            tvXiaohuoNum.setText(data.getCode());
            tvMudiNum.setText(data.getAddress());
//            tvZongliangNum.setText(data.getQuantity()+"");
            tvBeizhuNum.setText(data.getMemo());
            tv_cunhuo_num.setText(data.getDccf()+" "+data.getInventoryname());
            tv_chandi_num.setText(data.getCd());
            tv_kehu_num.setText(data.getPartnername());
            try {
                String quantity = data.getQuantity();
                if (!TextUtils.isEmpty(quantity)) {
                    Double aDouble = Double.valueOf(quantity);
                    String result = String.format("%.3f",aDouble);
                    tvZongliangNum.setText(result);
                }
            }catch (Exception e){
                LogUtil.print("fei",e.toString());
            }
        }
    }
}
